package com.company.huisuo.biz.adapter

import android.app.Activity
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.view.isVisible
import com.company.huisuo.base.BaseSingleAdapter
import com.company.huisuo.biz.activity.ArtistInfoActivity
import com.company.huisuo.biz.bean.ArtistBean
import com.company.huisuo.databinding.ItemArtistShowListBinding
import com.company.huisuo.ext.loadImg

/**
 * 艺人选秀列表
 */
class ArtistShowListAdapter : BaseSingleAdapter<ArtistBean, ItemArtistShowListBinding>() {

    private val mSelectList = arrayListOf<Int>()

    override val initViewBinding: (LayoutInflater, ViewGroup, Boolean) -> ItemArtistShowListBinding
        get() = ItemArtistShowListBinding::inflate

    override fun convert(
        holder: SingleViewHolder<ItemArtistShowListBinding>, position: Int, item: ArtistBean?
    ) {
        if (mSelectList.contains(position)) {
            holder.binding.tvPreSelect.isVisible = true
            holder.binding.tvSelect.text = "我就选Ta"
        } else {
            holder.binding.tvPreSelect.isVisible = false
            holder.binding.tvSelect.text = "艺人试台"
        }

        holder.binding.ivAvatar.loadImg(item?.avatar ?: 0)
        holder.binding.tvName.text = item?.name ?: ""
        holder.binding.tvDesc.text = item?.desc ?: ""

        holder.binding.ivAvatar.setOnClickListener {
            ArtistInfoActivity.start(context as Activity, item)
        }
        holder.binding.tvSelect.setOnClickListener {
            if (!mSelectList.contains(position)) {
                mSelectList.add(position)
                notifyItemChanged(position)
            }
        }
    }
}